package com.uzai.console.web.fd;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.fd.fdsendjob.FdSendJobDto;
import com.uzai.console.dto.fd.fdsendjob.FdSendJobIdDto;
import com.uzai.console.dto.fd.fdsendjob.FdSendJobQuery;
import com.uzai.console.dto.fd.fdtemplate.FdTemplateDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.mapper.JdTokenMapper;
import com.uzai.console.service.device.DeviceService;
import com.uzai.console.service.device.DeviceTypeService;
import com.uzai.console.service.fd.FdSendJobService;
import com.uzai.console.service.order.OrderReStatusService;
import com.uzai.console.service.order.OrderSourceService;
import com.uzai.console.service.order.OrderStatusService;
import com.uzai.console.service.user.UserService;
import com.uzai.console.service.wechatprivate.DeviceWechatInfoService;
import com.uzai.console.vo.fd.fdsendjob.FdSendJobVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发单发送任务
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "发送任务",tags = "个人微信|发单|发送任务")
@ApiSort(102)
@RestController
public class FdSendJobController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(FdSendJobController.class);

    @Autowired
    private FdSendJobService fdSendJobService;
    @Autowired
    private OrderStatusService orderStatusService;
    @Autowired
    private OrderReStatusService orderReStatusService;
    @Autowired
    private OrderSourceService orderSourceService;
    @Autowired
    private JdTokenMapper jdTokenMapper;
    @Autowired
    private DeviceWechatInfoService deviceWechatInfoService;
    @Autowired
    private UserService userService;
    @Autowired
    private DeviceTypeService deviceTypeService;
    @Autowired
    private DeviceService deviceService;

    @ApiOperation(value = "查询发单发送任务列表", notes = "查询发单发送任务列表", response = FdSendJobVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/fdSendJob/findFdSendJobList")
    public Object findFdSendJobList(@RequestBody FdSendJobQuery fdSendJobQuery){
        fdSendJobQuery.setParentId(0L); //只查询主任务
        return fdSendJobService.findFdSendJobList(fdSendJobQuery);
    }

    @ApiOperation(value = "查询发单发送任务详情", notes = "查询发单发送任务详情", response = FdSendJobVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/fdSendJob/findFdSendJobInfo")
    public Object findFdSendJobInfo(@RequestBody FdSendJobIdDto fdSendJobIdDto){
        return fdSendJobService.findFdSendJobInfo(fdSendJobIdDto);
    }

    @SystemLogType(model = SystemModelEnum.FdSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改发单发送任务", notes = "修改发单发送任务")
    @ApiOperationSupport(order = 4)
    @PostMapping("/fdSendJob/updateFdSendJob")
    public Object updateFdSendJob(@RequestBody FdSendJobDto fdSendJobDto){
        fdSendJobService.updateFdSendJob(fdSendJobDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.FdSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "开始发单发送任务", notes = "开始发单发送任务")
    @ApiOperationSupport(order = 5)
    @PostMapping("/fdSendJob/startFdSendJob")
    public Object startFdSendJob(@RequestBody FdSendJobIdDto fdSendJobIdDto){
        fdSendJobService.startFdSendJob(fdSendJobIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.FdSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "暂停发单发送任务", notes = "暂停发单发送任务")
    @ApiOperationSupport(order = 5)
    @PostMapping("/fdSendJob/pauseFdSendJob")
    public Object pauseFdSendJob(@RequestBody FdSendJobIdDto fdSendJobIdDto){
        fdSendJobService.pauseFdSendJob(fdSendJobIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.FdSendJob, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "结束发单发送任务", notes = "结束发单发送任务")
    @ApiOperationSupport(order = 6)
    @PostMapping("/fdSendJob/finishFdSendJob")
    public Object finishFdSendJob(@RequestBody FdSendJobIdDto fdSendJobIdDto){
        fdSendJobService.finishFdSendJob(fdSendJobIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.FdSendJob, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除发单发送任务", notes = "删除发单发送任务")
    @ApiOperationSupport(order = 7)
    @PostMapping("/fdSendJob/deleteFdSendJob")
    public Object deleteFdSendJob(@RequestBody FdSendJobIdDto fdSendJobIdDto){
        fdSendJobService.deleteFdSendJob(fdSendJobIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.FdTemplate, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "手动发送发单任务", notes = "手动发送发单任务")
    @ApiOperationSupport(order = 8)
    @PostMapping("/fdSendJob/addFdSendJob")
    public Object addFdSendJob(@RequestBody FdSendJobDto fdSendJobDto){
        fdSendJobService.addFdSendJob(fdSendJobDto);
        return true;
    }
    
}
